use std::sync::Arc;
use std::time::Instant;
use tokio::task;

#[tokio::main]
async fn main() {
    let url = "http://127.0.0.1:7878/";
    let total_requests = 1000;
    let concurrency = 100;
    
    let client = Arc::new(reqwest::Client::new());
    let start = Instant::now();
    
    let mut tasks = vec![];
    for _ in 0..concurrency {
        let client = Arc::clone(&client);
        tasks.push(task::spawn(async move {
            for _ in 0..(total_requests/concurrency) {
                let _ = client.get(url).send().await;
            }
        }));
    }
    
    for task in tasks {
        task.await.unwrap();
    }
    
    let duration = start.elapsed();
    println!("总请求数: {}", total_requests);
    println!("并发数: {}", concurrency);
    println!("总耗时: {:.2} 秒", duration.as_secs_f64());
    println!("每秒请求数: {:.2}", total_requests as f64 / duration.as_secs_f64());
}
